<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
  <meta charset="UTF-8">
  <title>添加店铺页面</title>
  <link rel="stylesheet" th:href="@{/layui/css/layui.css}"  >
</head>
<body>

<form class="layui-form" action="">
  <div class="layui-form-item">
    <label class="layui-form-label">店铺名称</label>
    <div class="layui-input-inline">
      <input type="text" name="storeName" required  lay-verify="required" placeholder="请输入店铺名称" autocomplete="off" class="layui-input">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">店铺地址</label>
    <div class="layui-input-block">
      <input type="text" name="storeAddress" required lay-verify="required" placeholder="请输入店铺地址" autocomplete="off" class="layui-input">
    </div>
  </div>

  <div class="layui-form-item">
    <label class="layui-form-label">联系电话</label>
    <div class="layui-input-inline">
      <input type="text" name="storeTel" required lay-verify="required" placeholder="请输入联系方式" autocomplete="off" class="layui-input">
    </div>
  </div>

  <div class="layui-form-item">
    <label class="layui-form-label">店长名称</label>
    <div class="layui-input-inline">
      <input type="text" name="storeManager" required lay-verify="required" placeholder="请输入店长名称" autocomplete="off" class="layui-input">
    </div>
  </div>

  <div class="layui-form-item">
    <label class="layui-form-label">服务状态</label>
    <div class="layui-input-block">
      <input  type="checkbox" name="storeStatus" value="1" lay-skin="switch">
    </div>
  </div>
  <div class="layui-form-item">
    <div class="layui-input-block">
      <button class="layui-btn" lay-submit lay-filter="addForm">立即提交</button>
      <button type="reset" class="layui-btn layui-btn-primary">重置</button>
    </div>
  </div>
</form>
<script th:src="@{/layui/layui.js}"></script>

<!--监听表单提交-->
<script>
  layui.form.on('submit(addForm)', function(data){
    //发送给后台，后台接受这些数据保存到数据库中
    var $ =  layui.jquery;
    $.ajax({
      method:'post',          /*请求方式 post（安全 数据量大）  get*/
      url:'/store/add.do',     /*谁来接受数据，也就是后台地址*/
      data: JSON.stringify(data.field), /* 发个后台的数据 */
      dataType:'text',        /*希望后台给咱们的数据格式*/
      contentType:'application/json', /*声明发送给后台的数据格式*/
      success:function (rs){
        layui.layer.msg('添加成功');
      }
    })
    return false;
  });
</script>
</body>
</html>